package com.freemyleft.left.zapp.selectimage.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.google.gson.Gson;
import com.zhy.autolayout.AutoLayoutActivity;

/**
 * Created by lybj on 2017/3/4.
 */
public abstract class BaseActivity extends AutoLayoutActivity {
    //test
    public static Activity mActivity;
    public Gson mGson = new Gson();
    public String mTag;
    public boolean mIsStatu = true;
    public boolean mIsDestory = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ActionBar actionBar=getSupportActionBar();
        if (actionBar!=null){
            actionBar.hide();
        }
        setContentView(getLayoutId(savedInstanceState));
        initBase();
        initView();
        initData();
        initListener();
    }
    @Override
    protected void onRestart() {
        super.onRestart();
        mActivity = this;
    }
    /**
     * 初始化
     */
    private void initBase() {
        mActivity = this;
        mTag = mActivity.getLocalClassName();
        if (mIsStatu){
//            setStatusBarTintResource();
        }
    }
    /**
     * 资源id
     */
    public abstract int getLayoutId(Bundle savedInstanceState);

    /**
     * 初始化布局
     */
    public abstract void initView();

    /**
     * 初始化数据
     */
    public void initData() {
    }

    /**
     * 初始化监听
     */
    public void initListener() {
    }


    /**
     * 显示Toast
     */
    public static void toast(String toast) {
        Toast.makeText(mActivity, toast, Toast.LENGTH_SHORT).show();
    }
    /*打印Json*/
    public void logJson(Object bean) {
        Log.e(mTag, "Json::" + mGson.toJson(bean));
    }
    /**
     * 通知栏颜色
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mIsDestory = true;
    }
    /**
     * 设置状态
     *
     */
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}